<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>订单详情</title>
<link href="<%=path %>/hplus/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
<link href="<%=path %>/hplus/css/plugins/iCheck/custom.css" rel="stylesheet">
<link href="<%=path %>/hplus/css/animate.min.css" rel="stylesheet">
<link href="<%=path %>/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/font-awesome.min93e3.css?v=4.4.0"/>
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/plugins/datapicker/datepicker3.css">
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css">
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/style.min.css"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet">
<style type="text/css">
body {font-size: 14px;padding: 20px;}
#condition{line-height: 34px;}
#condition .radio{line-height: 21px;}
#condition>div.row{margin-bottom: 8px;}
#condition a{color: black;margin-right: 12px;}
#condition a.cfoucs{color: #1ab394;font-weight: bold;}
.radio-primary input[type="radio"] + label::after {background-color: #1ab394;}
.radio-primary input[type="radio"]:checked + label::after {background-color: #1ab394;}
.radio-primary input[type="radio"]:checked + label::before {border-color: #1ab394;}
.ui-dialog-footer button.ui-dialog-autofocus{background-color: #18a689;border-color: #18a689;}
ol{
  		list-style:none;
  	}
  	li{
  		list-style:none;
  	}
form>div.row{margin-bottom: 16px;}
a.btn-rounded{margin-right: 16px;}
a:hover{
	background-color:red;
	color:red;
}
</style>
</head>
<body class="gray-bg">
<div class="container-fluid" style="padding-top: 40px;background-color: white;">
	<form method="get" class="form-horizontal">
		<div class="row">
			<label class="col-sm-2 control-label">完善会员信息：</label>
			<div class="col-sm-1 control-label" style="text-align: left;">手机号</div>
			<div class="col-sm-3">
		        <input id="phone" type="text" class="form-control" value="13426260001">
		    </div>
		</div>
		<div class="row">
			<div class="col-sm-offset-2 col-sm-1 control-label" style="text-align: left;">姓名</div>
			<div class="col-sm-3">
		        <input id="name" type="text" class="form-control">
		    </div>
		</div>
		<div class="row">
			<div class="col-sm-offset-2 col-sm-1 control-label" style="text-align: left;">性别</div>		
			<div class="col-sm-1">
	            <div class="radio radio-primary"  style="margin-left:0px;">
	                <input id="a" type="radio" name="sex" value="m" checked="checked">
	                <label for="a">男</label>
	            </div>
	        </div>
	        <div class="col-sm-1">
	            <div class="radio radio-primary" >
	                <input id="b" type="radio" name="sex" value="f">
	                <label for="b">女</label>
	            </div>
	        </div>
		</div>
		<div class="row">
			<div class="col-sm-offset-2 col-sm-1 control-label" style="text-align: left;">生日</div>
			<div class="col-sm-1">
	            <select class="form-control year" onchange="func_getDay()">
	            </select>
	        </div>
	        <div class="col-sm-1" style="padding-left:0px;">
	            <span style="line-height:34px;">年</span>
	        </div>
	        <div class="col-sm-1" style="margin-left: -80px;">
	            <select class="form-control month" onchange="func_getDay()">
	            </select>
	        </div>
	        <div class="col-sm-1" style="padding-left:0;">
	            <span style="line-height:34px;">月</span>
	        </div>
	        <div class="col-sm-1" style="margin-left: -80px;">
	            <select class="form-control day">
	            </select>
	        </div>
	        <div class="col-sm-1" style="padding-left:0;">
	            <span style="line-height:34px;">日</span>
	        </div>
		</div>
		<div class="row">
			
			<label class="col-sm-2 control-label">体质标签：</label>
			<div class="col-sm-8" >
				<div class="form-group" style="margin-left:100px;">					
					 <label class="col-sm-1 control-label"><input type="checkbox" id="tag1" value="老">&nbsp;老</label>
					 <label class="col-sm-1 control-label"><input type="checkbox" id="tag2" value="幼">&nbsp;幼</label>
					 <label class="col-sm-1 control-label"><input type="checkbox" id="tag3" value="孕">&nbsp;孕</label>
					 <label class="col-sm-1 control-label"><input type="checkbox" id="tag4" value="残">&nbsp;残</label>
                </div>
			</div>
		</div>
		<div class="row">
			<label class="col-sm-2 control-label">购药信息：</label>
			<div class="col-sm-1"></div>
			<div class="col-sm-8" id="medicine">
				<p>药品：扑尔敏片</p>
				<p>数量：1盒</p>
				<p>预计用药结束日期：10月5日</p>
				<p>药师顾问：吕晓虎</p>
			</div>
		</div>
		<div class="row" id="sms">	
			
		 <!-- <div class="tabs-container">
	    <ul class="nav nav-tabs">
	                <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">小票拦截统计</a>
	                </li>
	                <li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">小票拦截查询</a>
	                </li>
	                <li class=""><a data-toggle="tab" href="#tab-3" aria-expanded="false">小票弹窗</a>
	                </li>
	     </ul>
		     <div class="tab-content">
					<div class="ibox-content tab-pane active" id="tab-1">
					111111
					</div> 
					<div class="tab-pane " id="tab-2">
					22222
					</div>
				</div>
		</div> -->
		</div>
		<div class="row">
			<div class="col-sm-12 text-center">
				<button class="btn btn-primary" type="button" id="commit">确定</button>
			</div>
		</div>
	</form>
</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/2.2.1/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.16/js/jquery.dataTables.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/public.js"></script>
	<script src="<%=path%>/hplus/js/plugins/iCheck/icheck.min.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/artDialog/7.0.0/dialog-plus.js"></script>
<script type="text/javascript">
var path = "<%=path%>";
var id=getQueryString("id");
var access_token=$.cookie('access_token');
var cid=$.cookie('cid');
var uid=$.cookie('uid');
var orderInfo;
var name="";
$(function(){
	init();
	$(":checkbox").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});
	//$("#phone").keyup(function(){
		//var phone = $(this).val();
		var phone="13426260001";
		if(phone.length == 11){
			$.post(path+"/member/ajaxGetMemberByPhone",{phone:phone},function(data){
				if(data.status == "200"){
					var member = data.data;
					if(member != null){						
						$("#name").val(member.name);
						$("#name").attr("readOnly","true");
						$(":radio[name='sex'][value='"+member.gender+"']").attr("checked",true);
						$(":radio[name='sex']").attr("disabled",true);
						var birthday = member.birthday;
						if(birthday != null && birthday != ""){
							var birthdayArr = birthday.split("-");
							$(".year").val(birthdayArr[0]).attr("disabled",true);
							$(".month").val(birthdayArr[1]).attr("disabled",true);
							func_getDay();
							$(".day").val(birthdayArr[2]).attr("disabled",true);
						}
						name=member.name;
						dataInit();
					}else{
						$("#name").attr("readOnly",false);
						$(":radio[name='sex']").attr("disabled",false);
						$(".year").attr("disabled",false);
						$(".month").attr("disabled",false);
						$(".day").attr("disabled",false);
					}
				}
			},"json");
		}
	//});
});

function init(){
	func_getYear();
    func_getMonth();
    func_getDay();
    dataInit();
    //setInterval(getOrder,1000);
}
function func_getYear() {
    var now = new Date();
    var startYear = 1900;
    var endYear = now.getFullYear();

    var option = "";
    for (; startYear <= endYear; startYear++) {
        option += '<option value="' + startYear + '">' + startYear + '</option>';
    }
    $(".year").html(option);
}

function func_getMonth() {
    var option = "";
    for (var i = 1; i <= 12; i++) {
        option += '<option value="' + i + '">' + i + '</option>';
    }
    $(".month").html(option);
}

function func_getDay() {
    var year = $(".year:last").val();
    var month = $(".month:last").val();

    var now = new Date();
    now.setFullYear(year);
    now.setDate(1);
    now.setMonth(month);
    now.setDate(0);
    var lastDay = now.getDate();

    var option = "";
    for (var i = 1; i <= lastDay; i++) {
        option += '<option value="' + i + '">' + i + '</option>';
    }
    $(".day:last").html(option);
}
	function dataInit(){
		var orderUrl="<%=path%>/ser/order/findOrder";		
		$.ajax({url:orderUrl,
			type:"post",
			async:false,
			data:{"id":id},
			success:function(data){
				if(data!=null){				
					orderInfo=JSON.parse(data);	
					var json=JSON.parse(orderInfo.goods_name);
					func_medicine(json);
					$.ajax({
						url:"<%=path%>/ser/order/getSms",
						type:"post",
						async:false,
						data:{"orderId":id},
						success:function(data){	
							func_smsData(data);
						}
					});
				}
			}	
		});
	}
	function func_smsData(json){
		var data=JSON.parse(json);
		var	option="<label class='col-sm-2 control-label'>发送购药提醒：</label>";
			option+="<div id='sms' style='margin-left:350px;'><div class='tabs-container'>";
		  	option+="<ul class='nav nav-tabs'>";	
		for(var i=0;i<data.length;i++){
			if(i>0){
				option+=" <li class=''><a data-toggle='tab' href='#tab-1"+i+"' aria-expanded='false'>"+data[i].after_days+"天</a></li>";
			}else{
				option+=" <li class='active' style='margin-left: 15px;'><a data-toggle='tab' href='#tab-1"+i+"' aria-expanded='true'>"+data[i].after_days+"天</a></li>";
			}
		}
		option+="</ul><div class='tab-content'>";
		var goodsList=JSON.parse(orderInfo.goods_name);
		var goodsInfo="";
		var goodsName="";
		for(var i=0;i<goodsList.length;i++)
		{goodsInfo+=","+goodsList[i].goodsName+"、"+goodsList[i].purchaseQuantity+"盒";
			goodsName+=	goodsList[i].goodsName+",";
		}
		for(var i=0;i<data.length;i++){
			var content=data[i].content;
			if(name==null||name==""){
				name="会员";
			}
			content=content.replace("[autograph]",orderInfo.store_name);
			content=content.replace("[customerName]",name);
			content=content.replace("[tradeName]",goodsList[0].goodsName);
			content=content.replace("[tradeNum]",goodsList[0].purchaseQuantity+"盒");
			content = content.replace("[buyNum]",goodsList[0].purchaseQuantity+"盒");
			content=content.replace("[buyTime]",orderInfo.trade_time);
			content = content.replace("[attributeUrl]", " 属性链接 ");
    		content = content.replace("[appraiseUrl]", " 评价链接 ");
    		content = content.replace("[explainUrl]", " 说明链接 ");
    		content = content.replace("[couponCode]", " 优惠券码 ");
    		content = content.replace("[NameAndNum]", goodsInfo);
			if(i>0){
			option+="<div class='tab-pane' id='tab-1"+i+"'>";		
			option+="<div class='col-sm-10'>";
			option+="<textarea style='width: 100%;height: 120px;padding: 20px;' id='smsText' readonly='readonly'>"+content+"</textarea>";
			option+="</div></div>";
			}else{
				option+="<div class='tab-pane active' id='tab-1"+i+"'>";		
				option+="<div class='col-sm-10'>";
				option+="<textarea style='width: 100%;height: 120px;padding: 20px;' id='smsText' readonly='readonly'>"+content+"</textarea>";
				option+="</div></div>";
			}
		}  
		option+="</div></div></div>";
		$("#sms").html(option);
	}
	function func_medicine(data){
		var option="<p>";
		for(var i=0;i<data.length;i++){
			option+="药品："+data[i].goodsName+"</p>";
			option+="<p>数量："+data[i].purchaseQuantity+"</p>";
		}
		$("#medicine").html(option);
	}
	function func_sms(data){
		var name="会员";
		if($("#name").val()!=""){
			name=$("#name").val();
		}
		var option="";
		option+="["+data.store_name+"]"+"亲爱的"+name+",您于"+data.trade_time+"购买";
		var json=JSON.parse(data.goods_name);
		for(var i=0;i<json.length;i++){
			option+=json[i].goodsName+json[i].purchaseQuantity+"盒";
		}
		option+="请点击链接搜索关注微信号YATDYF,获取详细药品说明及健康资讯: http://ypk.39.net/885689/";
		$("#smsText").html(option);
	}
	function getTag(){
		var json="";
		if($("#tag1").is(":checked")){
			if($("#tag1").val()!=""){
				json+=$("#tag1").val()+",";
			}
		}
		if($("#tag2").is(":checked")){
			if($("#tag2").val()!=""){
				json+=$("#tag2").val()+",";
			}
		}
		if($("#tag3").is(":checked")){
			if($("#tag3").val()!=""){
				json+=$("#tag3").val()+",";
			}
		}
		if($("#tag4").is(":checked")){
			if($("#tag4").val()!=""){
				json+=$("#tag4").val()+",";
			}
		}
		if(json!=""){
			return json;
		}
		return null;
	}
	function func_artdialog(name,value){
 		var d = dialog({
 			title: name,
 			fixed: true,
 			width: 200,
 	        height:100,
 			content:"<center style='font-size:20px; line-height:100px;'>"+value+"</center>",
 			okValue: "确定",
 			ok: function () {
 				return true;
 			}
 		});
 		d.show();
 	}
	$("#commit").click(function(){
		var reg = /^1[0-9]{10}$/;
		name=$("#name").val();
		var phone=$("#phone").val();
		var sex=$('input:radio:checked').val();
		var date=$(".year").val()+"-"+$(".month").val()+"-"+$(".day").val();
		var tag=getTag();
		var url="<%=path%>/ser/order/updateOrder";
		if(phone==""){
			func_artdialog("提示","请输入手机号！");
		}else if(!reg.test(phone)){
			func_artdialog("提示","手机号格式不正确！");
		}else{
			$.post(url,{
				"uid":uid,
				"cid":cid,
				"id":id,
				"access_token":access_token,
				"consumerName":name,
				"consumerPhone":phone,
				"sex":sex,
				"tag":tag,
				"date":date
			},function(data){
				data=JSON.parse(data);
				if(data.msg_code=="0"){
				window.close();
				}else if(data.msg_code=="2"){
					func_artdialog("提示",data.msg_info);
					window.close();
				}else{
					func_artdialog("提示",data.msg_info);
				}
			});
		}
	})
</script>
</html>